/*
 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION!

import { int32, float32 } from "@koalaui/common"
import { KStringPtr, KBoolean, RuntimeType, runtimeType, isResource, isInstanceOf } from "@koalaui/interop"
import { NodeAttach, remember } from "@koalaui/runtime"
import { ComponentBase } from "./ComponentBase"
import { TypeChecker } from "#components"
import { ArkCommonMethodComponent } from "./ArkCommon"
import { ArkEmbeddedComponentPeer } from "./peers/ArkEmbeddedComponentPeer"
import { UseEventsProperties } from "./use_properties"
import { CommonMethod } from "./ArkCommonInterfaces"
import { EmbeddedComponentAttribute, TerminationInfo } from "./ArkEmbeddedComponentInterfaces"
import { Callback_TerminationInfo_Void } from "./SyntheticDeclarations"
import { ErrorCallback } from "./ArkIsolatedComponentInterfaces"
import { Want } from "./ArkArkuiExternalInterfaces"
import { EmbeddedType } from "./ArkEnumsInterfaces"
/** @memo:stable */
export class ArkEmbeddedComponentComponent extends ArkCommonMethodComponent {
    getPeer(): ArkEmbeddedComponentPeer {
        return (this.peer as ArkEmbeddedComponentPeer)
    }
    /** @memo */
    public setEmbeddedComponentOptions(loader: Want, type: EmbeddedType): this {
        if (this.checkPriority("setEmbeddedComponentOptions")) {
            const loader_casted = loader as (Want)
            const type_casted = type as (EmbeddedType)
            this.getPeer()?.setEmbeddedComponentOptionsAttribute(loader_casted, type_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onTerminated(value: ((parameter: TerminationInfo) => void)): this {
        if (this.checkPriority("onTerminated")) {
            const value_casted = value as (((parameter: TerminationInfo) => void))
            this.getPeer()?.onTerminatedAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onError(value: ErrorCallback): this {
        if (this.checkPriority("onError")) {
            const value_casted = value as (ErrorCallback)
            this.getPeer()?.onErrorAttribute(value_casted)
            return this
        }
        return this
    }
    public applyAttributesFinish(): void {
        // we calls this function outside of class, so need to make it public
        super.applyAttributesFinish()
    }
}

/** @memo */
export function ArkEmbeddedComponent(
  /** @memo */
  style: ((attributes: ArkEmbeddedComponentComponent) => void) | undefined,
  /** @memo */
  content_: (() => void) | undefined,
  loader: Want, type: EmbeddedType
) {
    const receiver = remember(() => {
        return new ArkEmbeddedComponentComponent()
    })
    NodeAttach<ArkEmbeddedComponentPeer>((): ArkEmbeddedComponentPeer => ArkEmbeddedComponentPeer.create(receiver), (_: ArkEmbeddedComponentPeer) => {
        receiver.setEmbeddedComponentOptions(loader,type)
        style?.(receiver)
        content_?.()
        receiver.applyAttributesFinish()
    })
}
